package views
{
	
	import assists.log.Log;
	import assists.resource.ResourceLoaderData;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import inerface.IHomePanel;
	
	import main.ClientConstants;
	import main.ViewSubBase;
	
	import message.NewsResult;
	
	import panel.home.HomePanel;
	
	
	public class HomeView extends ViewSubBase
	{
		private var _panel:IHomePanel;
		
		private var first:Boolean = true;
		
		public function HomeView()
		{
		}
		
		public override function show():void
		{
			view.guide.titleText = "首页";
			render();
			
			this.registerMessageHandler(NewsResult.CMD,backHandler);
			
		}
		
		private function backHandler(value:NewsResult):void
		{
			first = false;
			
			data.news.changeStore(value);
			
			_panel.changeData(data.news.newsList);
		}
		
		protected override function render():void
		{
			if(_panel == null){
				_panel = new HomePanel();
				_panel.onClose = close;
				_panel.onHelp = view.help.show;
				_panel.onViewPath = showPath;
				_panel.onShowMyPath = showMyPath;
				_panel.onShowGetMore = showGetMore;
				_panel.onLocation = view.navigationPos.show;//view.navigationTypeChoose.show;
				_panel.onShowWeather = showWeather;
				_panel.onNewsShowDetail = showNews;
				_panel.onSuntime = view.suntime.show;
				_panel.init(view.layout.stage,view.resourceLoader,lang);
			}
			
			
			if(first == true){
				data.news.getNewsFromServer();
			}
			
			_panel.changeData(data.news.newsList);
			
			this.addView(_panel);
		}
		
		public override function close():void
		{
			closeView(this);
		}
		
		public override function clear():void
		{
			this.cancelMessageHandler(NewsResult.CMD,backHandler);
			
			_panel.clear();
			
			first = false;
			
			_panel = null;
		}
		
		private function showPath():void
		{
			view.weico.show();
			//			view.testLocation.show();
			//			view.sysRecommendPathList.show();
		}
		
		private function showMyPath():void
		{
			//			view.selectPath.titleStr = "我的路线";
			//			view.selectPath.pathList = data.choosePath.elementList;
			//			view.selectPath.show();
			
			view.sysRecommendPathList.show();
		}
		
		private function showGetMore():void
		{
			view.getMore.show();
		}
		
		private function showWeather():void
		{
			view.eating.type = ClientConstants.DETAIL_COLLECT;
			view.eating.show();
			//			view.weatherInfo.show();
		}
		
		private function showNews(obj:Object):void
		{
			view.newsDetail.info = obj;
			view.newsDetail.show();
		}
	}
}